<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('cp list')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="form">
					<input type="hidden" id="pageFlag" name="pageFlag" th:value="${cp.pageFlag}"/>
					<div class="select-list">
						<ul>
							<li class="select-time">
								<label>考评月份： </label>
								<input type="text" class="" id="monthId" name="monthId" th:value="${cp.monthId}"/>
							</li>
							<li th:if="${'SUBMIT' == cp.pageFlag}">
								<input type="hidden" id="type" name="type" th:value="${cp.type}"/>
							</li>
							<li th:if="${'MANAGE' == cp.pageFlag}">
								测评表类型：
								<select name="type" id="type" th:with="dicts=${@dict.getType('rate_cp_type')}">
									<option value="">--请选择--</option>
									<option th:each="dict : ${dicts}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
										th:selected="${cp.type == dict.dictValue}"></option>
								</select>
							</li>
							<li>
								状态：
								<select name="status" id="status" th:with="dicts=${@dict.getType('rate_cp_status')}">
									<option value="">--请选择--</option>
									<option th:each="dict : ${dicts}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
										th:selected="${cp.status == dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								
								<a style="margin-left:20px;" class="btn btn-danger btn-rounded btn-sm" onclick="add()"
									th:if="${'SUBMIT' == cp.pageFlag}">
									<i class="fa fa-plus"></i> 新增
								</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: datetimepicker-js" />
	<script th:inline="javascript">
		var prefix = ctx + "rate/cp";
		var statusDict = [[${@dict.getType('rate_cp_status')}]];
		var typeDict = [[${@dict.getType('rate_cp_type')}]];
		var pageFlag = [[${cp.pageFlag}]];
		var type = [[${cp.type}]];

		$(function() {
			$("#monthId").datetimepicker({
				format: 'yyyy-mm',
				weekStart: 1,
				autoclose: true,
				startView: 3,
				minView: 3
			});
			list();
		});

		function list() {
			var options = {
				url: prefix + "/list",
				modalName: "cp",
				columns: [{
					field: 'id',
					visible: false
				},
				{
					field: 'type',
					align: 'center',
					title: '测评表类型',
					width: '10%',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(typeDict, value);
					}
				},
				{
					field: 'monthId',
					align: 'center',
					title: '考评月份',
					width: '10%'
				},
				{
					field: 'status',
					align: 'center',
					title: '当前状态',
					width: '10%',
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(statusDict, value);
					}
				},
				{
					field: 'createUser.userName',
					align: 'center',
					title: '提交人'
				},
				{
					field: 'dept.deptName',
					align: 'center',
					title: '提交部门'
				},
				{
					field: 'createTime',
					align: 'center',
					title: '提交时间'
				},
				{
					title: '操作',
					align: 'center',
					width: '30%',
					formatter: function(value, row, index) {
						var status = row.status;
						
						var actions = [];
						if ("SUBMIT" == pageFlag) {
							if ("DRAFT" == status) {
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submit(\'' + row.id + '\')"><i class="fa fa-check"></i>提交</a> ');
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="remove1(\'' + row.id + '\')"><i class="fa fa-times"></i>删除</a> ');
							} else {
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-edit"></i>编辑</a> ');
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-check"></i>提交</a> ');
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-times"></i>删除</a> ');
							}
						} else if ("MANAGE" == pageFlag) {
							if ("APPROVED" == status) {
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="cancelSubmit(\'' + row.id + '\')"><i class="fa fa-edit"></i>撤回</a> ');
							} else {
								actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-edit"></i>撤回</a> ');
							}
						}
						actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="view(\'' + row.id + '\')"><i class="fa fa-query"></i>查看</a> ');
						return actions.join('');
					}
				}]
			};
			$.table.init(options);
		}
		
		function add() {
			$.modal.openFull("新增",
					prefix + "/add?pageFlag=ADD&type=" + type);
		}
		function edit(id) {
			$.modal.openFull("修改",
					prefix + "/edit?id=" + id + "&pageFlag=EDIT");
		}
		function submit(id) {
			$.modal.confirm("确认要提交该条记录吗?", function() {
				var url = prefix + "/submit";
				var data = {"timestamp": new Date().getTime(), "id": id};
				$.operate.submit(url, "post", "json", data);
			});
		}
		function cancelSubmit(id) {
			$.modal.confirm("确认要撤回该条记录吗?", function() {
				var url = prefix + "/cancelSubmit";
				var data = {"timestamp": new Date().getTime(), "id": id};
				$.operate.submit(url, "post", "json", data);
			});
		}
		function view(id) {
			$.modal.openFull("查看",
					prefix + "/edit?id=" + id + "&pageFlag=VIEW");
		}
		function remove1(id) {
			$.modal.confirm("确认要删除该条记录吗?", function() {
				var url = prefix + "/delete/" + id;
				var data = {"timestamp": new Date().getTime()};
				$.operate.submit(url, "post", "json", data);
			});
		}
	</script>
</body>
</html>